home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15922 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.1 KB

  1. Path: news.nyu.edu!schonberg!dewar
  2. From: dewar@cs.nyu.edu (Robert Dewar)
  3. Newsgroups: comp.lang.ada,comp.lang.c,comp.lang.c++,comp.edu
  4. Subject: Re: ANSI C and POSIX (was Re: C/C++ knocks the crap out of Ada)
  5. Date: 8 Apr 1996 15:48:12 -0400
  6. Organization: Courant Institute of Mathematical Sciences
  7. Message-ID: <dewar.828992408@schonberg>
  8. References: <JSA.96Feb16135027@organon.com> <dewar.828757752@schonberg> <danpop.828819479@rscernix> <dewar.828879781@schonberg> <4k9qhe$65r@solutions.solon.com> <dewar.828936837@schonberg> <828964950snz@genesis.demon.co.uk> <4kbfup$2vd@news1.mnsinc.com> <4kbl5i$p3@mordred.gatech.edu>
  9. NNTP-Posting-Host: schonberg.cs.nyu.edu
  10. X-Newsreader: NN version 6.5.0 (NOV)
  11.  
  12. James says
  13.  
  14. "No. When it says "undefined", it means "undefined". There's no way to make
  15. undefined behavior portable, that's why it's undefined."
  16.  
  17. Actually, things are not quite so simple. In practice compiler vendors
  18. often go to quite a bit of trouble to make sure that things that people
  19. expect to work, do in fact work they way they expect, even if the standard
  20. says that the behavior is undefined. For example, in Fortran-66, it was
  21. undefined what happened in a DO loop if the end-points were the "wrong"
  22. way round, but in practice the expectation was that the loop would execute
  23. once, so all F66 compilers I know work that way. Similarly in Fortran,
  24. people expect large arrays to be passed by reference, and count on it, so
  25. even though the standard says that it is undefined whether they are passed
  26. by reference or value, all compilers do in fact use pass by reference and
  27. a lot of highly portable code depends on this fact. Highly portable here
  28. is not some kind of theoretical label about conformance, it is an empirical
  29. observation that the code works on all platforms.
  30.  
  31. Almost all languages have some level of expectations about what works that
  32. go beyond the standard. For example, in C, people do all sorts of things
  33. with pointers that are undefined in ANSI terms, and yet the resulting
  34. programs are in fact highly portable.
  35.  
  36. In Ada, as another example, there is a strong expectation that if an
  37. out parameter is not assigned in a procedure, then its valud is undefined
  38. and should not be accessed on return, but in fact it is permissible to
  39. raise Program_Error in this case. Ada/Ed used to do this, and it caused
  40. major chaos with a lot of otherwise portable programs. Yes, the programs
  41. were technically wrong, but in the real world, Ada/Ed changed, not all
  42. the programs out there.
  43.  
  44. A competent compiler tries to implement 100% of the required standard
  45. functionality, plus as much as possible of the expected behavior that
  46. goes beyond this standard, consistent with not damaging the quality
  47. of code, or the performance of the compiler, too severely.
  48.  
  49. The examples above are just scattered examples, every language I know
  50. has quite a long list of such "common beliefs" that are in fact wrong.
  51.  
  52. A more delicate problem arises when an existing compiler has bugs with
  53. respect to the standard, and you are trying to be compatible with both
  54. the standard and the existing compiler. In this case, some delicate
  55. compromises may be necessary.
  56.  
  57.